Skip to main content

First Step to Create Value Contract

To begin writing a Value Contract (VC), you’ll need to set up the development environment and follow a series of steps to define your contract's structure.

Prerequisites

Basic Knowledge of C++: Contracts are typically written in C++, so familiarity with the language is beneficial. It’s recommended to use VS Code for ease of use, but any code editor will work.

Decide Contract Name

The first step is to decide on a name for your Value Contract. For this guide, we'll use "database" as an example.

Naming Convention*

Choose descriptive and intuitive names for your Value Contract.

Create a directory with the name of your contract:

mkdir database
cd database

Inside this directory, create two files:

  • database.hpp (header file)
  • database.cpp (source file)

You can create these files directly through the terminal or within your code editor.

touch database.hpp database.cpp

Define Constructor in Header File

Open the database.hpp file and start by defining the structure of your contract.

Begin by including necessary headers, followed by the contract definition:

database.hpp
#pragma once
#include <inery/inery.hpp>

using namespace inery;

CONTRACT database : public contract {
public:
using contract::contract;

// Constructor for the 'database' contract
database(name receiver, name code, datastream<const char*> ds)
: contract(receiver, code, ds) {}

// Add further definitions here
};

Here’s a breakdown of what each part does:

  • #pragma once: Ensures the header file is included only once during compilation.
  • inery/inery.hpp: Imports core functionality required for Inery VC.
  • CONTRACT database : public contract: This is the main contract class, extending the contract class from the Inery framework.
  • using namespace inery;: Allows access to the Inery namespace for contract development.
  • database(name receiver, name code, datastream<const char*> ds): Constructor for the 'database' contract, defining the contract's name and data stream.
  • contract(receiver, code, ds): Calls the parent contract constructor with the provided parameters.

Include header file

The constructor is defined in the header file itself, now include hpp file in database.cpp to ensure easy access and simplicity.

database.cpp

#include "database.hpp"

// Add further definitions here

Now you have successfully defined the initial structure of your Value Contract. Continue by adding services and compositions to expand its capabilities.